@echo off

echo ***************************************************************************
echo Scrit to automate running of the selenium tests
echo @author: rsammeta@playstation.sony.com
echo ***************************************************************************
      
if "%OS%" == "Windows_NT" setlocal enableextensions enabledelayedexpansion

if not "%MASHUP_TESTING_LIB%" == "" (
	if  exist "%MASHUP_TESTING_LIB%\selenium-server-standalone-2.12.0.jar" (
		goto getNumOfTests
	) else (
		goto getLibPath
	)
) else (
	goto getLibPath
)

:getLibPath

	echo.
	echo To avoid this prompt, set the MASHUP_TESTING_LIB environment variable under Advanced System Settings.
	set /p MASHUP_TESTING_LIB= Enter a valid path to mashup testing lib directory (Example, C:\MyWorkspace\MashupTesting\trunk\lib) :   
	
	if  exist "%MASHUP_TESTING_LIB%\selenium-server-standalone-2.12.0.jar" goto getNumOfTests
		goto getLibPath

:getNumOfTests

	echo.
	set /p numOfTests= Enter the valid number of tests you want to run : 
	set /a tempVar=numOfTests

	if !tempVar! equ 0 (
	  if !numOfTests! equ 0 (
		goto runTests		
	  ) else (
		goto getNumOfTests		
	  )
	) else (
	  goto runTests	  
	)		
		
:runTests

	set /a i=0
	set /a portNumber=4445

	:loopTests
	
		if %i%==%numOfTests% goto end
			echo Running test number %i%.
			start cmd.exe /K "java -jar "%MASHUP_TESTING_LIB%\selenium-server-standalone-2.12.0.jar" -firefoxProfileTemplate "C:\Selenium\SelProfile" -role node -hub http://10.91.25.63:4444/grid/register -port %portNumber%"
			set /a i=%i%+1
			set /a portNumber=%portNumber%+1
			goto loopTests

:end	
	


